/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package muddb.entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;


/**
 *
 * @author keith
 */
@Entity
@Table( name = "skill" )
@IdClass( SkillPK.class )
@NamedQueries( { @NamedQuery( name = "Skill.findBySkillId", query =
                                                            "SELECT s FROM Skill s WHERE s.skillId = :skillId" ),
                 @NamedQuery( name = "Skill.findBySkillGrpId", query =
                                                               "SELECT s FROM Skill s WHERE s.skillGrpId = :skillGrpId" ),
                 @NamedQuery( name = "Skill.findBySkillName", query =
                                                              "SELECT s FROM Skill s WHERE s.skillName = :skillName" ),
                 @NamedQuery( name = "Skill.findBySkillClassDef", query =
                                                                  "SELECT s FROM Skill s WHERE s.skillClassDef = :skillClassDef" ) } )
public class Skill implements Serializable {
  private static final long serialVersionUID = 1L;
  private int skillId;
  private int skillGrpId;
  private String skillName;
  private String skillClassDef;
  private SkillGroup skillGroup;
  private Collection<SkillProf> skillProfCollection;


  public Skill() {
  }


  public Skill( String skillName ) {
    this.skillName = skillName;
  }


  public Skill(  int skillId, int skillGrpId, String skillName, String skillClassDef ) {
    this(skillId,skillGrpId);
    this.skillName = skillName;
    this.skillClassDef = skillClassDef;
  }


  public Skill( int skillId, int skillGrpId ) {
    this.skillId = skillId;
    this.skillGrpId = skillGrpId;
  }




  @Id
  @Column(name = "skill_grp_id", nullable = false)
  public int getSkillGrpId() {
    return skillGrpId;
  }

  public void setSkillGrpId(int skillGrpId) {
    this.skillGrpId = skillGrpId;
  }

  @Id
  @GeneratedValue(strategy = GenerationType.SEQUENCE)
  @Column(name = "skill_id", nullable = false)
  public int getSkillId() {
    return skillId;
  }

  public void setSkillId(int skillId) {
    this.skillId = skillId;
  }

  @Column( name = "skill_name", length=30, nullable = false )
  public String getSkillName() {
    return skillName;
  }


  public void setSkillName( String skillName ) {
    this.skillName = skillName;
  }


  @Column(name = "skill_class_def", length = 50, nullable = true)
  public String getSkillClassDef() {
    return skillClassDef;
  }


  public void setSkillClassDef( String skillClassDef ) {
    this.skillClassDef = skillClassDef;
  }


  @JoinColumn(name = "skill_grp_id", referencedColumnName = "skill_grp_id", insertable = false, updatable = false)
  @ManyToOne
  public SkillGroup getSkillGroup() {
    return skillGroup;
  }


  public void setSkillGroup( SkillGroup skillGroup ) {
    this.skillGroup = skillGroup;
  }


  @OneToMany(cascade = CascadeType.ALL, mappedBy = "skill")
  public Collection<SkillProf> getSkillProfCollection() {
    return skillProfCollection;
  }


  public void setSkillProfCollection( Collection<SkillProf> skillProfCollection ) {
    this.skillProfCollection = skillProfCollection;
  }


  @Override
  public int hashCode() {
    int hash = 0;
    hash += (int) skillId;
    hash += (int) skillGrpId;
    return hash;
  }


  @Override
  public boolean equals( Object object ) {
    // TODO: Warning - this method won't work in the case the id fields are not set
    if ( !( object instanceof Skill ) ) {
      return false;
    }
    Skill other = (Skill) object;
    if ( this.skillId != other.skillId ) {
      return false;
    }
    if ( this.skillGrpId != other.skillGrpId ) {
      return false;
    }
    return true;
  }


  @Override
  public String toString() {
    return "muddb.entities.Skill[skillId=" + skillId + ", skillGrpId=" + skillGrpId + "]";
  }

}
